package com.woniuxy.service.table;

import com.github.pagehelper.PageHelper;
import com.woniuxy.entity.Indent;
import com.woniuxy.mapper.BedMapper;
import com.woniuxy.mapper.IndentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 马踏东京赏樱花
 */
@Service
public class TableDataServiceImpl implements TableDataService {
    @Autowired
    private BedMapper bedMapper;
    @Autowired
    private IndentMapper indentMapper;

    @Override
    public int findBedsSum() {
        int beds = bedMapper.findAllBeds();
        return beds;
    }

    @Override
    public int bedsCount() {
        int indents = indentMapper.findAllIndent();
        return indents;
    }

    @Override
    public List<Indent> findAll() {
        List<Indent> indents = indentMapper.selectByExample(null);
        if (indents.size() > 0) {
            return indents;
        }
        throw new RuntimeException("数据为空");

    }

    @Override
    public List<Indent> findPage(int page, int size) {
        PageHelper.startPage(page, size);
        List<Indent> indentList = indentMapper.selectByExample(null);
        if (indentList.size() == 0) {
            throw new RuntimeException("数据为空");
        }
        return indentList; // 返回分页后的数据
    }
}
